package com.xuxu.blog.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xuxu.blog.dao.FileDao;
import com.xuxu.blog.entity.FileEntity;
import com.xuxu.blog.service.DownLoadService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.yaml.snakeyaml.events.Event;

import javax.annotation.Resource;

/**
 * @className: DownLoadServiceImpl
 * @author: Maxuxu
 * @date: 2022/8/28 15:39
 * @description:
 */
@Service
@Slf4j
public class DownLoadServiceImpl implements DownLoadService {
    @Resource
    FileDao fileDao;
    @Resource
    FileServiceImpl fileService;

    /**
     * 基于id查询对应文件
     * @return
     */
    @Override
    public FileEntity FindFilesById(Integer id) {
        FileEntity fileEntity = fileDao.selectById(id);
        return fileEntity;
    }

    @Override
    public Page<FileEntity> FindByPage(Integer pageNum, Integer size, String name, String type) {
        QueryWrapper<FileEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("is_delete", false);
        wrapper.eq("enable", true);
        wrapper.orderByDesc("id");
        // 动态sql，有哪个查询条件就查哪个，没有就查询所有
        if (!"".equals(name)) {
            wrapper.like("name", name);
        }
        if (!"".equals(type)){
            wrapper.like("type", type);
        }
        Page<FileEntity> page = fileService.page(new Page<>(pageNum, size),wrapper);

        return page;
    }
}
